package GUILayer;

import ControlLayer.SaleItemCtr;

import ModelLayer.RealException;
import ModelLayer.SaleItemRecords;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.BoxLayout;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.CardLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import ModelLayer.SaleItem;

public class SaleItemUI extends JPanel {

	private static final long serialVersionUID = 1L;

	private SaleItemCtr saleItemCrt;

	private JTextField showNameField;
	private JTextField showBarcodeField;
	private JTextField showLocationField;
	private JTextField showBPriceField;
	private JTextField showSPriceField;

	private JTextField editLocationField;
	private JTextField editNameField;
	private JTextField editBPriceField;
	private JTextField editSPriceField;
	private JTextField editMinStockField;
	private JTextField editMaxStockField;
	private JTextField editCurrStockField;
	private JTextField editDiscountQField;
	private JTextField editContractorIDField;
	private JTextField editUMField;
	private JTextField editTaxField;
	private JTextField editBarcodeField;
	private JPanel editSaleItem;

	private DefaultTableModel tableModel;
	private JTable table;

	private JPanel showSaleItem;
	private JPanel showAllSaleItems;
	private JPanel SaleItem;
	private JTextField showAllIdField;

	private JTextField createLocationField;
	private JTextField createNameField;
	private JTextField createBPriceField;
	private JTextField createSPriceField;
	private JTextField createTaxField;
	private JTextField createUMField;
	private JTextField createMinStockField;
	private JTextField createMaxStockField;
	private JTextField createCurrStockField;
	private JTextField createDiscountQField;
	private JTextField createContractorIDField;
	private JPanel createSaleItem;

	private JPanel SaleItemContainer;
	private JTextField showUMField;
	private JTextField showTaxField;
	private JTextField showMinStockField;
	private JTextField showMaxStockField;
	private JTextField showCurStockField;
	private JTextField showDiscountQField;
	private JTextField showContractorIDField;

	public SaleItemUI() {
		saleItemCrt = new SaleItemCtr();
		initialize();
	}

	public void initialize() {

		String loggedInPosition = LoginUI.getLoggedInPosition();

		tableModel = new DefaultTableModel() {
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isCellEditable(int row, int column) {
				return false;
			}
		};
		tableModel.addColumn("Barcode");
		tableModel.addColumn("Name");
		tableModel.addColumn("Price");
		tableModel.addColumn("Stock");
		this.setLayout(new BorderLayout(0, 0));

		JTabbedPane subMenu = new SubMenuTabbedPane();
		this.add(subMenu, BorderLayout.CENTER);

		SaleItem = new JPanel();
		subMenu.addTab("Sale Item", null, SaleItem, null);
		SaleItem.setLayout(new BorderLayout(0, 0));

		JPanel showAllMenu = new JPanel();
		SaleItem.add(showAllMenu, BorderLayout.NORTH);
		showAllMenu.setLayout(new BorderLayout(0, 0));
		showAllMenu.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "Sale Item Menu",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));

		JPanel showAllMenuLeft = new JPanel();
		showAllMenu.add(showAllMenuLeft, BorderLayout.WEST);

		if (loggedInPosition.equals("admin")
				|| loggedInPosition.equals("manager")) {
			JButton btnCreateNewSaleItem = new JButton("Create new Sale Item");
			btnCreateNewSaleItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					CardLayout cl = (CardLayout) SaleItemContainer.getLayout();
					cl.show(SaleItemContainer, "createSaleItem");
				}
			});
			showAllMenuLeft.add(btnCreateNewSaleItem);
		}

		JPanel showAllMenuRight = new JPanel();
		showAllMenu.add(showAllMenuRight, BorderLayout.EAST);

		JLabel showAllIdLbl = new JLabel("Barcode:");
		showAllMenuRight.add(showAllIdLbl);

		showAllIdField = new JTextField();
		showAllMenuRight.add(showAllIdField);
		showAllIdField.setColumns(10);

		JButton showAllBtnSearch = new JButton("Search");
		showAllBtnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				showSaleItem(showAllIdField.getText());
				showAllIdField.setText("");
			}
		});
		showAllMenuRight.add(showAllBtnSearch);

		SaleItemContainer = new JPanel();
		SaleItem.add(SaleItemContainer);
		SaleItemContainer.setLayout(new CardLayout(0, 0));

		showSaleItem = new JPanel();
		SaleItemContainer.add(showSaleItem, "showSaleItem");
		showSaleItem.setLayout(new BorderLayout(0, 0));

		JPanel showSaleItemInfoContainer = new JPanel();
		showSaleItem.add(showSaleItemInfoContainer, BorderLayout.NORTH);
		showSaleItemInfoContainer.setLayout(new FlowLayout(FlowLayout.CENTER,
				5, 5));
		showSaleItemInfoContainer.setBorder(new TitledBorder(null,
				"Sale Item Info", TitledBorder.LEADING, TitledBorder.TOP, null,
				null));

		JPanel showSaleItemInfo = new JPanel();
		showSaleItemInfo.setLayout(new BoxLayout(showSaleItemInfo,
				BoxLayout.X_AXIS));
		showSaleItemInfoContainer.add(showSaleItemInfo);

		JPanel showSaleItemLeft = new JPanel();
		showSaleItemInfo.add(showSaleItemLeft);
		showSaleItemLeft.setLayout(new GridLayout(0, 1, 0, 0));

		JPanel showBarcodeLabelPanel = new JPanel();
		showBarcodeLabelPanel.setLayout(new BoxLayout(showBarcodeLabelPanel,
				BoxLayout.X_AXIS));
		showSaleItemLeft.add(showBarcodeLabelPanel);

		JLabel showBarcodeLabel = new JLabel("Barcode");
		showBarcodeLabelPanel.add(showBarcodeLabel);
		showBarcodeLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showNameLabelPanel = new JPanel();
		showNameLabelPanel.setLayout(new BoxLayout(showNameLabelPanel,
				BoxLayout.X_AXIS));
		showSaleItemLeft.add(showNameLabelPanel);

		JLabel showNameLabel = new JLabel("Name");
		showNameLabelPanel.add(showNameLabel);
		showNameLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showLocationLabelPanel = new JPanel();
		showLocationLabelPanel.setLayout(new BoxLayout(showLocationLabelPanel,
				BoxLayout.X_AXIS));
		showSaleItemLeft.add(showLocationLabelPanel);

		JLabel showLocationLabel = new JLabel("Location");
		showLocationLabelPanel.add(showLocationLabel);
		showLocationLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showBuyPriceLabelPanel = new JPanel();
		showBuyPriceLabelPanel.setLayout(new BoxLayout(showBuyPriceLabelPanel,
				BoxLayout.X_AXIS));
		showSaleItemLeft.add(showBuyPriceLabelPanel);

		JLabel showBuyPriceLabel = new JLabel("Buy Price");
		showBuyPriceLabelPanel.add(showBuyPriceLabel);
		showBuyPriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showSaleItemLabelPanel = new JPanel();
		showSaleItemLabelPanel.setLayout(new BoxLayout(showSaleItemLabelPanel,
				BoxLayout.X_AXIS));
		showSaleItemLeft.add(showSaleItemLabelPanel);

		JLabel showSalePriceLabel = new JLabel("Sale Price");
		showSaleItemLabelPanel.add(showSalePriceLabel);
		showSalePriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showTaxLabelPanel = new JPanel();
		showSaleItemLeft.add(showTaxLabelPanel);

		JLabel showTaxLabel = new JLabel("Tax");
		showTaxLabelPanel.add(showTaxLabel);
		showTaxLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showUMLabelPanel = new JPanel();
		showSaleItemLeft.add(showUMLabelPanel);

		JLabel showUMLabel = new JLabel("U. M.");
		showUMLabelPanel.add(showUMLabel);
		showUMLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showMinimStockLabelPanel = new JPanel();
		showSaleItemLeft.add(showMinimStockLabelPanel);

		JLabel shwoMinimStockLabel = new JLabel("Min. St.");
		showMinimStockLabelPanel.add(shwoMinimStockLabel);
		shwoMinimStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showMaxStockLabelPanel = new JPanel();
		showSaleItemLeft.add(showMaxStockLabelPanel);

		JLabel showMaxStockLabel = new JLabel("Max. St.");
		showMaxStockLabel.setHorizontalAlignment(SwingConstants.CENTER);
		showMaxStockLabelPanel.add(showMaxStockLabel);

		JPanel showCurrentStockLabelPanel = new JPanel();
		showSaleItemLeft.add(showCurrentStockLabelPanel);

		JLabel showCurrentStockLabel = new JLabel("Cur. St.");
		showCurrentStockLabel.setHorizontalAlignment(SwingConstants.CENTER);
		showCurrentStockLabelPanel.add(showCurrentStockLabel);

		JPanel showDiscountQLabelPanel = new JPanel();
		showSaleItemLeft.add(showDiscountQLabelPanel);

		JLabel showDiscountQLabel = new JLabel("Discount. Q");
		showDiscountQLabelPanel.add(showDiscountQLabel);
		showDiscountQLabel.setHorizontalAlignment(SwingConstants.CENTER);

		JPanel showContractorIDLabelPanel = new JPanel();
		showSaleItemLeft.add(showContractorIDLabelPanel);

		JLabel showContractorIDLabel = new JLabel("Contractor ID.");
		showContractorIDLabelPanel.add(showContractorIDLabel);
		showContractorIDLabel.setHorizontalAlignment(SwingConstants.CENTER);

		// Show Right

		JPanel showSaleItemRight = new JPanel();
		showSaleItemRight.setLayout(new BoxLayout(showSaleItemRight,
				BoxLayout.Y_AXIS));
		showSaleItemInfo.add(showSaleItemRight);

		JPanel showBarcodeFieldPanel = new JPanel(new FlowLayout(
				FlowLayout.LEFT));
		showSaleItemRight.add(showBarcodeFieldPanel);

		showBarcodeField = new JTextField();
		showBarcodeFieldPanel.add(showBarcodeField);
		showBarcodeField.setHorizontalAlignment(SwingConstants.CENTER);
		showBarcodeField.setEditable(false);
		showBarcodeField.setColumns(10);

		JPanel showNameFieldPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		showSaleItemRight.add(showNameFieldPanel);

		showNameField = new JTextField();
		showNameFieldPanel.add(showNameField);
		showNameField.setHorizontalAlignment(SwingConstants.CENTER);
		showNameField.setEditable(false);
		showNameField.setColumns(25);

		JPanel showLocationFieldPanel = new JPanel(new FlowLayout(
				FlowLayout.LEFT));
		showSaleItemRight.add(showLocationFieldPanel);

		showLocationField = new JTextField();
		showLocationFieldPanel.add(showLocationField);
		showLocationField.setHorizontalAlignment(SwingConstants.CENTER);
		showLocationField.setEditable(false);
		showLocationField.setColumns(20);

		JPanel showBPriceFieldPanel = new JPanel(
				new FlowLayout(FlowLayout.LEFT));
		showSaleItemRight.add(showBPriceFieldPanel);

		showBPriceField = new JTextField();
		showBPriceFieldPanel.add(showBPriceField);
		showBPriceField.setHorizontalAlignment(SwingConstants.CENTER);
		showBPriceField.setEditable(false);
		showBPriceField.setColumns(15);

		JPanel showSPriceFieldPanel = new JPanel(
				new FlowLayout(FlowLayout.LEFT));
		showSaleItemRight.add(showSPriceFieldPanel);

		showSPriceField = new JTextField();
		showSPriceFieldPanel.add(showSPriceField);
		showSPriceField.setHorizontalAlignment(SwingConstants.CENTER);
		showSPriceField.setEditable(false);
		showSPriceField.setColumns(5);

		JPanel showUMFieldPanel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) showUMFieldPanel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showUMFieldPanel);

		showUMField = new JTextField();
		showUMField.setHorizontalAlignment(SwingConstants.CENTER);
		showUMField.setEditable(false);
		showUMField.setColumns(5);
		showUMFieldPanel.add(showUMField);

		JPanel showTaxFieldPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		showSaleItemRight.add(showTaxFieldPanel);

		showTaxField = new JTextField();
		showTaxField.setHorizontalAlignment(SwingConstants.CENTER);
		showTaxField.setEditable(false);
		showTaxField.setColumns(5);
		showTaxFieldPanel.add(showTaxField);

		JPanel showMinStockFieldPanel = new JPanel();
		FlowLayout flowLayout_1 = (FlowLayout) showMinStockFieldPanel
				.getLayout();
		flowLayout_1.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showMinStockFieldPanel);

		showMinStockField = new JTextField();
		showMinStockField.setHorizontalAlignment(SwingConstants.CENTER);
		showMinStockField.setEditable(false);
		showMinStockField.setColumns(5);
		showMinStockFieldPanel.add(showMinStockField);

		JPanel showMaxStockFieldPanel = new JPanel();
		FlowLayout flowLayout_2 = (FlowLayout) showMaxStockFieldPanel
				.getLayout();
		flowLayout_2.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showMaxStockFieldPanel);

		showMaxStockField = new JTextField();
		showMaxStockField.setHorizontalAlignment(SwingConstants.CENTER);
		showMaxStockField.setEditable(false);
		showMaxStockField.setColumns(5);
		showMaxStockFieldPanel.add(showMaxStockField);

		JPanel showCurStockFieldPanel = new JPanel();
		FlowLayout flowLayout_3 = (FlowLayout) showCurStockFieldPanel
				.getLayout();
		flowLayout_3.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showCurStockFieldPanel);

		showCurStockField = new JTextField();
		showCurStockField.setHorizontalAlignment(SwingConstants.CENTER);
		showCurStockField.setEditable(false);
		showCurStockField.setColumns(5);
		showCurStockFieldPanel.add(showCurStockField);

		JPanel showDiscountQFieldPanel = new JPanel();
		FlowLayout flowLayout_4 = (FlowLayout) showDiscountQFieldPanel
				.getLayout();
		flowLayout_4.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showDiscountQFieldPanel);

		showDiscountQField = new JTextField();
		showDiscountQField.setHorizontalAlignment(SwingConstants.CENTER);
		showDiscountQField.setEditable(false);
		showDiscountQField.setColumns(5);
		showDiscountQFieldPanel.add(showDiscountQField);

		JPanel showContractorIDFieldPanel = new JPanel();
		FlowLayout flowLayout_5 = (FlowLayout) showContractorIDFieldPanel
				.getLayout();
		flowLayout_5.setAlignment(FlowLayout.LEFT);
		showSaleItemRight.add(showContractorIDFieldPanel);

		showContractorIDField = new JTextField();
		showContractorIDField.setHorizontalAlignment(SwingConstants.CENTER);
		showContractorIDField.setEditable(false);
		showContractorIDField.setColumns(5);
		showContractorIDFieldPanel.add(showContractorIDField);

		JPanel showBottomMenu = new JPanel();
		showSaleItem.add(showBottomMenu, BorderLayout.CENTER);
		showBottomMenu.setLayout(new BorderLayout(0, 0));

		JPanel showBottomMenuRight = new JPanel();
		showBottomMenu.add(showBottomMenuRight, BorderLayout.CENTER);

		if (loggedInPosition.equals("admin")
				|| loggedInPosition.equals("manager")) {
			JButton showBtnEdit = new JButton("Edit");
			showBtnEdit.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					editSaleItem(showBarcodeField.getText());
				}
			});
			showBottomMenuRight.add(showBtnEdit);

			JButton showBtnDelete = new JButton("Delete");
			showBtnDelete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int reply = JOptionPane.showConfirmDialog(null,
							"Are you sure you want to delete this Sale Item ?",
							"Delete SaleItem", JOptionPane.YES_NO_OPTION,
							JOptionPane.WARNING_MESSAGE);
					if (reply == JOptionPane.YES_OPTION) {
						boolean success = true;
						try {
							saleItemCrt.deleteSaleItem(showBarcodeField
									.getText());
						} catch (NumberFormatException e1) {
							success = false;
							JOptionPane.showMessageDialog(null,
									"Field value invalid", "Error",
									JOptionPane.ERROR_MESSAGE);
						} catch (RealException e1) {
							success = false;
							JOptionPane.showMessageDialog(null, e1.getError(),
									"Error", JOptionPane.ERROR_MESSAGE);
						}
						if (success) {
							JOptionPane.showMessageDialog(null,
									"The item was deleted", "Delete Sale Item",
									JOptionPane.INFORMATION_MESSAGE);
							showAllSaleItems();
						}
					}
				}
			});
			showBottomMenuRight.add(showBtnDelete);

		}

		JPanel showBottomMenuLeft = new JPanel();
		showBottomMenu.add(showBottomMenuLeft, BorderLayout.WEST);

		JButton showBtnBack = new JButton("Back");
		showBtnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				showAllSaleItems();
			}
		});
		showBottomMenuLeft.add(showBtnBack);

		if (loggedInPosition.equals("admin")
				|| loggedInPosition.equals("manager")) {
			editSaleItem = new JPanel();
			SaleItemContainer.add(editSaleItem, "editSaleItem");
			editSaleItem.setLayout(new BorderLayout(0, 0));

			JPanel editSaleItemInfoContainer = new JPanel();
			editSaleItem.add(editSaleItemInfoContainer, BorderLayout.NORTH);
			editSaleItemInfoContainer.setLayout(new FlowLayout(
					FlowLayout.CENTER, 5, 5));
			editSaleItemInfoContainer.setBorder(new TitledBorder(null,
					"Edit Sale Item", TitledBorder.LEADING, TitledBorder.TOP,
					null, null));

			JPanel editSaleItemInfo = new JPanel();
			editSaleItemInfo.setLayout(new BoxLayout(editSaleItemInfo,
					BoxLayout.X_AXIS));
			editSaleItemInfoContainer.add(editSaleItemInfo);

			// LEFT!!!!!!!!!!!!!

			JPanel editSaleItemLeft = new JPanel();
			editSaleItemInfo.add(editSaleItemLeft);
			editSaleItemLeft.setLayout(new GridLayout(0, 1, 0, 0));

			JPanel editBarcodeLabelPanel = new JPanel();
			editBarcodeLabelPanel.setLayout(new BoxLayout(
					editBarcodeLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editBarcodeLabelPanel);
			JLabel editBarcodeLabel = new JLabel("Barcode");
			editBarcodeLabelPanel.add(editBarcodeLabel);
			editBarcodeLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editNameLabelPanel = new JPanel();
			editNameLabelPanel.setLayout(new BoxLayout(editNameLabelPanel,
					BoxLayout.X_AXIS));
			editSaleItemLeft.add(editNameLabelPanel);
			JLabel editNameLabel = new JLabel("Name");
			editNameLabelPanel.add(editNameLabel);
			editNameLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editLocationLabelPanel = new JPanel();
			editLocationLabelPanel.setLayout(new BoxLayout(
					editLocationLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editLocationLabelPanel);
			JLabel editLocationLabel = new JLabel("Location");
			editLocationLabelPanel.add(editLocationLabel);
			editLocationLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editBPriceLabelPanel = new JPanel();
			editBPriceLabelPanel.setLayout(new BoxLayout(editBPriceLabelPanel,
					BoxLayout.X_AXIS));
			editSaleItemLeft.add(editBPriceLabelPanel);
			JLabel editBPriceLabel = new JLabel("BPrice");
			editBPriceLabelPanel.add(editBPriceLabel);
			editBPriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editSPriceLabelPanel = new JPanel();
			editSPriceLabelPanel.setLayout(new BoxLayout(editSPriceLabelPanel,
					BoxLayout.X_AXIS));
			editSaleItemLeft.add(editSPriceLabelPanel);
			JLabel editSPriceLabel = new JLabel("SPrice");
			editSPriceLabelPanel.add(editSPriceLabel);
			editSPriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editTaxLabelPanel = new JPanel();
			editTaxLabelPanel.setLayout(new BoxLayout(editTaxLabelPanel,
					BoxLayout.X_AXIS));
			editSaleItemLeft.add(editTaxLabelPanel);
			JLabel editTaxLabel = new JLabel("Tax");
			editTaxLabelPanel.add(editTaxLabel);
			editTaxLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editUMLabelPanel = new JPanel();
			editUMLabelPanel.setLayout(new BoxLayout(editUMLabelPanel,
					BoxLayout.X_AXIS));
			editSaleItemLeft.add(editUMLabelPanel);
			JLabel editUMLabel = new JLabel("UM");
			editUMLabelPanel.add(editUMLabel);
			editUMLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editminStockLabelPanel = new JPanel();
			editminStockLabelPanel.setLayout(new BoxLayout(
					editminStockLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editminStockLabelPanel);
			JLabel editminStockLabel = new JLabel("minStock");
			editminStockLabelPanel.add(editminStockLabel);
			editminStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editMaxStockLabelPanel = new JPanel();
			editMaxStockLabelPanel.setLayout(new BoxLayout(
					editMaxStockLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editMaxStockLabelPanel);
			JLabel editMaxStockLabel = new JLabel("MaxStock");
			editMaxStockLabelPanel.add(editMaxStockLabel);
			editMaxStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editCurrStockLabelPanel = new JPanel();
			editCurrStockLabelPanel.setLayout(new BoxLayout(
					editCurrStockLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editCurrStockLabelPanel);
			JLabel editCurrStockLabel = new JLabel("CurrStock");
			editCurrStockLabelPanel.add(editCurrStockLabel);
			editCurrStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editDiscountQLabelPanel = new JPanel();
			editDiscountQLabelPanel.setLayout(new BoxLayout(
					editDiscountQLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editDiscountQLabelPanel);
			JLabel editDiscountQLabel = new JLabel("DiscountQ");
			editDiscountQLabelPanel.add(editDiscountQLabel);
			editDiscountQLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel editContractorIDLabelPanel = new JPanel();
			editContractorIDLabelPanel.setLayout(new BoxLayout(
					editContractorIDLabelPanel, BoxLayout.X_AXIS));
			editSaleItemLeft.add(editContractorIDLabelPanel);
			JLabel editContractorIDLabel = new JLabel("ContractorID");
			editContractorIDLabelPanel.add(editContractorIDLabel);
			editContractorIDLabel.setHorizontalAlignment(SwingConstants.CENTER);

			// RIGHT EDIT

			JPanel editSaleItemRight = new JPanel();
			editSaleItemRight.setLayout(new BoxLayout(editSaleItemRight,
					BoxLayout.Y_AXIS));
			editSaleItemInfo.add(editSaleItemRight);

			JPanel editBarcodeFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editBarcodeFieldPanel);
			editBarcodeField = new JTextField();
			editBarcodeField.setEditable(false);
			editBarcodeFieldPanel.add(editBarcodeField);
			editBarcodeField.setHorizontalAlignment(SwingConstants.CENTER);
			editBarcodeField.setColumns(10);

			JPanel editNameFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editNameFieldPanel);
			editNameField = new JTextField();
			editNameFieldPanel.add(editNameField);
			editNameField.setHorizontalAlignment(SwingConstants.CENTER);
			editNameField.setColumns(15);

			JPanel editLocationFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editLocationFieldPanel);
			editLocationField = new JTextField();
			editLocationFieldPanel.add(editLocationField);
			editLocationField.setHorizontalAlignment(SwingConstants.CENTER);
			editLocationField.setColumns(15);

			JPanel editBPriceFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editBPriceFieldPanel);
			editBPriceField = new JTextField();
			editBPriceFieldPanel.add(editBPriceField);
			editBPriceField.setHorizontalAlignment(SwingConstants.CENTER);
			editBPriceField.setColumns(15);

			JPanel editSPriceFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editSPriceFieldPanel);
			editSPriceField = new JTextField();
			editSPriceFieldPanel.add(editSPriceField);
			editSPriceField.setHorizontalAlignment(SwingConstants.CENTER);
			editSPriceField.setColumns(5);

			JPanel editTaxFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editTaxFieldPanel);
			editTaxField = new JTextField();
			editTaxFieldPanel.add(editTaxField);
			editTaxField.setHorizontalAlignment(SwingConstants.CENTER);
			editTaxField.setColumns(5);

			JPanel editUMFieldPanel = new JPanel(
					new FlowLayout(FlowLayout.LEFT));
			editSaleItemRight.add(editUMFieldPanel);
			editUMField = new JTextField();
			editUMFieldPanel.add(editUMField);
			editUMField.setHorizontalAlignment(SwingConstants.CENTER);
			editUMField.setColumns(5);

			JPanel editMinStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editMinStockFieldPanel);
			editMinStockField = new JTextField();
			editMinStockFieldPanel.add(editMinStockField);
			editMinStockField.setHorizontalAlignment(SwingConstants.CENTER);
			editMinStockField.setColumns(5);

			JPanel editMaxStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editMaxStockFieldPanel);
			editMaxStockField = new JTextField();
			editMaxStockFieldPanel.add(editMaxStockField);
			editMaxStockField.setHorizontalAlignment(SwingConstants.CENTER);
			editMaxStockField.setColumns(5);

			JPanel editCurrStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editCurrStockFieldPanel);
			editCurrStockField = new JTextField();
			editCurrStockFieldPanel.add(editCurrStockField);
			editCurrStockField.setHorizontalAlignment(SwingConstants.CENTER);
			editCurrStockField.setColumns(5);

			JPanel editDiscountQFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editDiscountQFieldPanel);
			editDiscountQField = new JTextField();
			editDiscountQFieldPanel.add(editDiscountQField);
			editDiscountQField.setHorizontalAlignment(SwingConstants.CENTER);
			editDiscountQField.setColumns(5);

			JPanel editContractorIDFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			editSaleItemRight.add(editContractorIDFieldPanel);
			editContractorIDField = new JTextField();
			editContractorIDFieldPanel.add(editContractorIDField);
			editContractorIDField.setHorizontalAlignment(SwingConstants.CENTER);
			editContractorIDField.setColumns(5);

			JPanel editButtonsPanel = new JPanel();
			editSaleItem.add(editButtonsPanel, BorderLayout.CENTER);
			editButtonsPanel.setLayout(new BorderLayout(0, 0));

			JPanel editCenterButtonsPanel = new JPanel();
			editButtonsPanel.add(editCenterButtonsPanel, BorderLayout.CENTER);

			JButton editBtnEdit = new JButton("Edit");
			editBtnEdit.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int reply = JOptionPane.showConfirmDialog(null,
							"Are you sure you want to edit this sale item ?",
							"Edit SaleItem", JOptionPane.YES_NO_OPTION,
							JOptionPane.WARNING_MESSAGE);
					if (reply == JOptionPane.YES_OPTION) {
						boolean success = true;
						try {
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 1,
									editNameField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 2,
									editBPriceField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 3,
									editSPriceField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 4,
									editTaxField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 5,
									editUMField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 6,
									editMinStockField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 7,
									editMaxStockField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 8,
									editCurrStockField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 9,
									editDiscountQField.getText());
							saleItemCrt.updateSaleItem(
									editBarcodeField.getText(), 10,
									editLocationField.getText());
						} catch (NumberFormatException e1) {
							success = false;
							JOptionPane.showMessageDialog(null,
									"Field value invalid", "Error",
									JOptionPane.ERROR_MESSAGE);
						} catch (RealException e1) {
							success = false;
							JOptionPane.showMessageDialog(null, e1.getError(),
									"Error", JOptionPane.ERROR_MESSAGE);
						}
						if (success) {
							JOptionPane.showMessageDialog(null,
									"The sale item was edited",
									"Edit SaleItem",
									JOptionPane.INFORMATION_MESSAGE);
							showSaleItem(showBarcodeField.getText());
						}
					}
				}
			});
			editCenterButtonsPanel.add(editBtnEdit);

			JButton editBtnCancel = new JButton("Cancel");
			editBtnCancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					showSaleItem(editBarcodeField.getText());
				}
			});
			editCenterButtonsPanel.add(editBtnCancel);

			createSaleItem = new JPanel();
			SaleItemContainer.add(createSaleItem, "createSaleItem");
			createSaleItem.setLayout(new BorderLayout(0, 0));

			JPanel createSaleItemInfoContainer = new JPanel();
			createSaleItem.add(createSaleItemInfoContainer, BorderLayout.NORTH);
			createSaleItemInfoContainer.setLayout(new FlowLayout(
					FlowLayout.CENTER, 5, 5));
			createSaleItemInfoContainer.setBorder(BorderFactory
					.createTitledBorder("Create sale item"));

			JPanel createSaleItemInfo = new JPanel();
			createSaleItemInfo.setLayout(new BoxLayout(createSaleItemInfo,
					BoxLayout.X_AXIS));
			createSaleItemInfoContainer.add(createSaleItemInfo);

			// create Left

			JPanel createSaleItemLeft = new JPanel();
			createSaleItemInfo.add(createSaleItemLeft);
			createSaleItemLeft.setLayout(new GridLayout(0, 1, 0, 0));

			JPanel createNameLabelPanel = new JPanel();
			createNameLabelPanel.setLayout(new BoxLayout(createNameLabelPanel,
					BoxLayout.X_AXIS));
			createSaleItemLeft.add(createNameLabelPanel);
			JLabel createNameLabel = new JLabel("Name");
			createNameLabelPanel.add(createNameLabel);
			createNameLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createLocationLabelPanel = new JPanel();
			createLocationLabelPanel.setLayout(new BoxLayout(
					createLocationLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createLocationLabelPanel);
			JLabel createLocationLabel = new JLabel("Location");
			createLocationLabelPanel.add(createLocationLabel);
			createLocationLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createBPriceLabelPanel = new JPanel();
			createBPriceLabelPanel.setLayout(new BoxLayout(
					createBPriceLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createBPriceLabelPanel);
			JLabel createBPriceLabel = new JLabel("BPrice");
			createBPriceLabelPanel.add(createBPriceLabel);
			createBPriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createSPriceLabelPanel = new JPanel();
			createSPriceLabelPanel.setLayout(new BoxLayout(
					createSPriceLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createSPriceLabelPanel);
			JLabel createSPriceLabel = new JLabel("SPrice");
			createSPriceLabelPanel.add(createSPriceLabel);
			createSPriceLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createTaxLabelPanel = new JPanel();
			createTaxLabelPanel.setLayout(new BoxLayout(createTaxLabelPanel,
					BoxLayout.X_AXIS));
			createSaleItemLeft.add(createTaxLabelPanel);
			JLabel createTaxLabel = new JLabel("Tax");
			createTaxLabelPanel.add(createTaxLabel);
			createTaxLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createUMLabelPanel = new JPanel();
			createUMLabelPanel.setLayout(new BoxLayout(createUMLabelPanel,
					BoxLayout.X_AXIS));
			createSaleItemLeft.add(createUMLabelPanel);
			JLabel createUMLabel = new JLabel("UM");
			createUMLabelPanel.add(createUMLabel);
			createUMLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createMinStockLabelPanel = new JPanel();
			createMinStockLabelPanel.setLayout(new BoxLayout(
					createMinStockLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createMinStockLabelPanel);
			JLabel createMinStockLabel = new JLabel("MinStock");
			createMinStockLabelPanel.add(createMinStockLabel);
			createMinStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createMaxStockLabelPanel = new JPanel();
			createMaxStockLabelPanel.setLayout(new BoxLayout(
					createMaxStockLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createMaxStockLabelPanel);
			JLabel createMaxStockLabel = new JLabel("MaxStock");
			createMaxStockLabelPanel.add(createMaxStockLabel);
			createMaxStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createCurrStockLabelPanel = new JPanel();
			createCurrStockLabelPanel.setLayout(new BoxLayout(
					createCurrStockLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createCurrStockLabelPanel);
			JLabel createCurrStockLabel = new JLabel("CurrStock");
			createCurrStockLabelPanel.add(createCurrStockLabel);
			createCurrStockLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createDiscountQLabelPanel = new JPanel();
			createDiscountQLabelPanel.setLayout(new BoxLayout(
					createDiscountQLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createDiscountQLabelPanel);
			JLabel createDiscountQLabel = new JLabel("DiscountQ");
			createDiscountQLabelPanel.add(createDiscountQLabel);
			createDiscountQLabel.setHorizontalAlignment(SwingConstants.CENTER);

			JPanel createContractorIDLabelPanel = new JPanel();
			createContractorIDLabelPanel.setLayout(new BoxLayout(
					createContractorIDLabelPanel, BoxLayout.X_AXIS));
			createSaleItemLeft.add(createContractorIDLabelPanel);
			JLabel createContractorIDLabel = new JLabel("ContractorID");
			createContractorIDLabelPanel.add(createContractorIDLabel);
			createContractorIDLabel
					.setHorizontalAlignment(SwingConstants.CENTER);

			// create Right

			JPanel createSaleItemRight = new JPanel();
			createSaleItemRight.setLayout(new BoxLayout(createSaleItemRight,
					BoxLayout.Y_AXIS));
			createSaleItemInfo.add(createSaleItemRight);

			JPanel createNameFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createNameFieldPanel);
			createNameField = new JTextField();
			createNameFieldPanel.add(createNameField);
			createNameField.setHorizontalAlignment(SwingConstants.CENTER);
			createNameField.setColumns(20);

			JPanel createLocationFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createLocationFieldPanel);
			createLocationField = new JTextField();
			createLocationFieldPanel.add(createLocationField);
			createLocationField.setHorizontalAlignment(SwingConstants.CENTER);
			createLocationField.setColumns(25);

			JPanel createBPriceFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createBPriceFieldPanel);
			createBPriceField = new JTextField();
			createBPriceFieldPanel.add(createBPriceField);
			createBPriceField.setHorizontalAlignment(SwingConstants.CENTER);
			createBPriceField.setColumns(7);

			JPanel createSpriceFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createSpriceFieldPanel);
			createSPriceField = new JTextField();
			createSpriceFieldPanel.add(createSPriceField);
			createSPriceField.setHorizontalAlignment(SwingConstants.CENTER);
			createSPriceField.setColumns(7);

			JPanel createTaxFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createTaxFieldPanel);
			createTaxField = new JTextField();
			createTaxFieldPanel.add(createTaxField);
			createTaxField.setHorizontalAlignment(SwingConstants.CENTER);
			createTaxField.setColumns(25);

			JPanel createUMFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createUMFieldPanel);
			createUMField = new JTextField();
			createUMFieldPanel.add(createUMField);
			createUMField.setHorizontalAlignment(SwingConstants.CENTER);
			createUMField.setColumns(25);

			JPanel createMinStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createMinStockFieldPanel);
			createMinStockField = new JTextField();
			createMinStockFieldPanel.add(createMinStockField);
			createMinStockField.setHorizontalAlignment(SwingConstants.CENTER);
			createMinStockField.setColumns(25);

			JPanel createMaxStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createMaxStockFieldPanel);
			createMaxStockField = new JTextField();
			createMaxStockFieldPanel.add(createMaxStockField);
			createMaxStockField.setHorizontalAlignment(SwingConstants.CENTER);
			createMaxStockField.setColumns(25);

			JPanel createCurrStockFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createCurrStockFieldPanel);
			createCurrStockField = new JTextField();
			createCurrStockFieldPanel.add(createCurrStockField);
			createCurrStockField.setHorizontalAlignment(SwingConstants.CENTER);
			createCurrStockField.setColumns(25);

			JPanel createDiscountQFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createDiscountQFieldPanel);
			createDiscountQField = new JTextField();
			createDiscountQFieldPanel.add(createDiscountQField);
			createDiscountQField.setHorizontalAlignment(SwingConstants.CENTER);
			createDiscountQField.setColumns(25);

			JPanel createContractorIDFieldPanel = new JPanel(new FlowLayout(
					FlowLayout.LEFT));
			createSaleItemRight.add(createContractorIDFieldPanel);
			createContractorIDField = new JTextField();
			createContractorIDFieldPanel.add(createContractorIDField);
			createContractorIDField
					.setHorizontalAlignment(SwingConstants.CENTER);
			createContractorIDField.setColumns(25);

			JPanel createBottomMenu = new JPanel();
			createSaleItem.add(createBottomMenu, BorderLayout.CENTER);
			createBottomMenu.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

			JButton createBtnCreate = new JButton("Create");
			createBottomMenu.add(createBtnCreate);

			createBtnCreate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					boolean success = true;
					try {
						saleItemCrt.createSaleItem(
								createNameField.getText(),
								Integer.parseInt(createLocationField.getText()),
								Double.parseDouble(createBPriceField.getText()),
								Double.parseDouble(createSPriceField.getText()),
								Double.parseDouble(createTaxField.getText()),
								createUMField.getText(),
								Integer.parseInt(createMinStockField.getText()),
								Integer.parseInt(createMaxStockField.getText()),
								Integer.parseInt(createCurrStockField.getText()),
								Integer.parseInt(createDiscountQField.getText()),
								Integer.parseInt(createContractorIDField
										.getText()));
					} catch (NumberFormatException e1) {
						success = false;
						JOptionPane.showMessageDialog(null,
								"Field value invalid", "Error",
								JOptionPane.ERROR_MESSAGE);
					} catch (RealException e1) {
						success = false;
						JOptionPane.showMessageDialog(null, e1.getError(),
								"Error", JOptionPane.ERROR_MESSAGE);
					}
					if (success) {
						JOptionPane.showMessageDialog(null,
								"The sale item was created", "Create SaleItem",
								JOptionPane.INFORMATION_MESSAGE);
						showAllSaleItems();
					}
				}
			});

			JButton createBtnCancel = new JButton("Cancel");
			createBtnCancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					showAllSaleItems();
				}
			});
			createBottomMenu.add(createBtnCancel);

		}

		showAllSaleItems = new JPanel();
		SaleItemContainer.add(showAllSaleItems, "showAllSaleItems");
		showAllSaleItems.setLayout(new BorderLayout(0, 0));

		JPanel showAllSaleItemsPanel = new JPanel();
		showAllSaleItemsPanel.setBorder(BorderFactory
				.createTitledBorder("All sale items"));
		showAllSaleItems.add(showAllSaleItemsPanel, BorderLayout.CENTER);

		table = new JTable(tableModel);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

		table.setAutoCreateRowSorter(true);

		table.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				int row = table.rowAtPoint(e.getPoint());
				if (e.getClickCount() == 2) {
					showSaleItem(String.valueOf((String) tableModel.getValueAt(
							row, 0)));
				}
			}
		});
		showAllSaleItemsPanel.setLayout(new BoxLayout(showAllSaleItemsPanel,
				BoxLayout.X_AXIS));

		JScrollPane scrollPane = new JScrollPane();
		showAllSaleItemsPanel.add(scrollPane);

		scrollPane.setViewportView(table);

		JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button");
		scrollPane.setColumnHeaderView(rdbtnNewRadioButton);

		showAllSaleItems();
	}

	protected void showSaleItem(String barcode) {
		boolean success = true;
		ModelLayer.SaleItem saleItem = null;
		try {
			saleItem = SaleItemRecords.getInstance().getSaleItem(barcode);
		} catch (RealException e) {
			success = false;
			JOptionPane.showMessageDialog(null, e.getError(), "Error",
					JOptionPane.ERROR_MESSAGE);
		}
		if (success) {
			showBarcodeField.setText(saleItem.getBarcode());
			showLocationField.setText(Long.toString(saleItem.getLocation()));
			showNameField.setText(saleItem.getName());
			showBPriceField.setText(Double.toString(saleItem.getbPrice()));
			showSPriceField.setText(Double.toString(saleItem.getsPrice()));
			showTaxField.setText(Double.toString(saleItem.getTax()));
			showMinStockField.setText(Integer.toString(saleItem.getMinStock()));
			showMaxStockField.setText(Integer.toString(saleItem.getMaxStock()));
			showUMField.setText(saleItem.getUm());
			showCurStockField.setText(Integer.toString(saleItem.getCurrStock()));
			showDiscountQField.setText(Integer.toString(saleItem.getDiscountQ()));
			CardLayout cl = (CardLayout) (SaleItemContainer.getLayout());
			showContractorIDField.setText(Integer.toString(saleItem
					.getContractor().getId()));
			cl.show(SaleItemContainer, "showSaleItem");
		}
	}

	protected void editSaleItem(String barcode) {
		ModelLayer.SaleItem saleItem = null;
		boolean success = true;
		try {
			saleItem = SaleItemRecords.getInstance().getSaleItem(barcode);
		} catch (RealException e) {
			success = false;
			JOptionPane.showMessageDialog(null, e.getError(), "Error",
					JOptionPane.ERROR_MESSAGE);
		}
		if (success) {
			editBarcodeField.setText(saleItem.getBarcode());
			editNameField.setText(saleItem.getName());
			editLocationField.setText(Integer.toString(saleItem.getLocation()));
			editBPriceField.setText(Double.toString(saleItem.getbPrice()));
			editSPriceField.setText(Double.toString(saleItem.getsPrice()));
			editTaxField.setText(Double.toString(saleItem.getTax()));
			editUMField.setText(saleItem.getUm());
			editMinStockField.setText(Integer.toString(saleItem.getMinStock()));
			editMaxStockField.setText(Integer.toString(saleItem.getMaxStock()));
			editDiscountQField
					.setText(Integer.toString(saleItem.getDiscountQ()));
			editCurrStockField
					.setText(Integer.toString(saleItem.getCurrStock()));
			editContractorIDField.setText(Double.toString(saleItem
					.getContractor().getId()));
			CardLayout cl = (CardLayout) (SaleItemContainer.getLayout());
			cl.show(SaleItemContainer, "editSaleItem");
		}
	}

	protected void showAllSaleItems() {
		ArrayList<ModelLayer.SaleItem> saleItems = SaleItemRecords
				.getInstance().getSaleItemRecords();
		tableModel.setRowCount(0);
		for (SaleItem saleItem : saleItems) {
			tableModel.addRow(new Object[] { saleItem.getBarcode(),
					saleItem.getName(), saleItem.getsPrice(),
					saleItem.getCurrStock() });
		}
		CardLayout cl_SaleItemContainer = (CardLayout) (SaleItemContainer
				.getLayout());
		cl_SaleItemContainer.show(SaleItemContainer, "showAllSaleItems");
	}

}
